//
//  HSClassRoomCell.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/10/11.
//  Copyright © 2016年 赖虹宇. All rights reserved.
//

import UIKit

class HSClassRoomCell: UITableViewCell {
    //头像
    var iconImage = UIImageView()
    //标题
    var titleName = UILabel()
    //科目
    var subjectName = UIButton()
    //教师名
    var tName = UILabel()
    //发布时间
    var creatTime = UILabel()
    
    var classRoomVM : HSClassRoomModel? {
        didSet {
            if classRoomVM?.usersex == "男" {
                iconImage.hy_lsetImage(url: "tboy", placeholderImage: "tboy", size: CGSize(width: 60, height: 60))
            }else{
                iconImage.hy_lsetImage(url: "tgirl", placeholderImage: "tgirl", size: CGSize(width: 60, height: 60))
            }
            titleName.text = classRoomVM?.picgroupname
            subjectName.setTitle(classRoomVM?.course, for: .normal)
            tName.text = classRoomVM?.username
            creatTime.text = classRoomVM?.creattime
            
        }
    }
   
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    fileprivate func setupUI(){
        //自定义设置UI
        //头像
        addSubview(iconImage)
        iconImage.snp.makeConstraints { (make) in
            make.left.top.equalTo(16)
            make.width.height.equalTo(60)
            
        }
        //标题
         titleName.font = UIFont.systemFont(ofSize: 17)
         titleName.textColor = UIColor().colorWithHex(0x4c4c4c)
        addSubview(titleName)
         titleName.snp.makeConstraints { (make) in
            make.top.equalTo(iconImage.snp.top)
            make.left.equalTo(iconImage.snp.right).offset(8)
            
        }
        //科目名
        subjectName.layer.cornerRadius = 10
        subjectName.setTitleColor(UIColor().colorWithHex(0x97fd7ff), for: .normal)
        subjectName.layer.borderColor = UIColor().colorWithHex(0x97fd7ff).cgColor
        subjectName.layer.borderWidth = 1
        subjectName.titleLabel?.font = UIFont.systemFont(ofSize: 11)
        addSubview(subjectName)
        subjectName.snp.makeConstraints { (make) in
            make.top.equalTo(titleName.snp.bottom).offset(8)
            make.left.equalTo(titleName.snp.left)
            make.width.equalTo(44)
            make.height.equalTo(20)
        }
        
        //老师名
        tName.font = UIFont.systemFont(ofSize: 15)
        tName.textColor = UIColor().colorWithHex(0x4c4c4c)
        addSubview(tName)
        tName.snp.makeConstraints { (make) in
            make.right.equalTo(-16)
            make.top.equalTo(iconImage.snp.top)
            
        }
        //发布时间
        creatTime.font = UIFont.systemFont(ofSize: 15)
        creatTime.textColor = UIColor().colorWithHex(0xcccccc)
        addSubview(creatTime)
        creatTime.snp.makeConstraints { (make) in
            make.top.equalTo(tName.snp.bottom).offset(8)
            make.right.equalTo(tName.snp.right)
        }
    }
}
